package com.example.bookManagement.Service;


import com.example.bookManagement.Mapper.BookInfoMapper;
import com.example.bookManagement.Model.BookInfo;
import com.example.bookManagement.Model.PageRequest;
import com.example.bookManagement.Model.PageResult;
import com.example.bookManagement.enmus.BookStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class BookService {
    @Autowired
    private BookInfoMapper bookInfoMapper;
    public Integer insertBook(BookInfo bookInfo) {
        return  bookInfoMapper.insertBook(bookInfo);
    }

    public PageResult<BookInfo> getBookListByPage(PageRequest pageRequest) {
        Integer count = bookInfoMapper.count();
        List<BookInfo> books = bookInfoMapper.queryBookListByPage(pageRequest);
        for(BookInfo bookInfo : books) {
                bookInfo.setStatusCN(BookStatus.getNameByCode(bookInfo.getStatus()).getName());
        }
        return new PageResult<>(count, books,pageRequest);
    }

    public BookInfo queryBookById(Integer bookId) {

        return bookInfoMapper.queryBookById(bookId);
    }

    public void updateBook(BookInfo bookInfo) {
        bookInfoMapper.updateBook(bookInfo);
    }
    public void batchDeleteBook(List<Integer> ids) {
        bookInfoMapper.batchDeleteBook(ids);
    }
}
